#include <iostream>
#include <vector>

using namespace std;
vector<string> a;
const int N = 110;
int flag[N][N];
int n, m;
int ret;
int dx[8]={1,0,1,-1,0,-1,1,-1};
int dy[8]={0,1,1,0,-1,-1,-1,1};
void dfs(int x, int y) {
    for(int i = 0; i < 8; i++) {
        int row = x + dx[i], col = y + dy[i];
        if(row >= 0 && row < n && col >= 0 && col < m && flag[row][col] == 0 && a[row][col] == 'W') {
            flag[row][col] = -1;
            dfs(row, col);
        }
    }
    return ;
}
int main() {
    cin >> n >>m;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        a.push_back(s);
    }
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(a[i][j] == 'W' && flag[i][j] == 0) {
                ret++;
                flag[i][j] = -1;
                dfs(i, j);
            }
        }
    }
    cout << ret;
    return 0;
}